package com.huhu.extras;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.huhu.GameActivity;
import com.huhu.manager.ResourcesManager;
import com.huhu.manager.SceneManager;

public class GameOverWindow extends Sprite{
	private Sprite spriteNavigator;
	private Sprite spriteReplay;

	public GameOverWindow(VertexBufferObjectManager vbom){
		super(0, 0, GameActivity.CAMERA_WIDTH, GameActivity.CAMERA_HEIGHT, ResourcesManager.getInstance().gameover_window_region, vbom);
		setColor(0, 0, 0);
		this.setAlpha(0.5f);
		attachButton(vbom);
	}
	
	private void attachButton(VertexBufferObjectManager vbom){
		spriteNavigator = new Sprite(GameActivity.CAMERA_WIDTH/2-ResourcesManager.getInstance().navigator_lose_region.getWidth()/2, GameActivity.CAMERA_HEIGHT/2-ResourcesManager.getInstance().navigator_win_region.getHeight()/2, ResourcesManager.getInstance().navigator_lose_region, vbom);
		attachChild(spriteNavigator);
		
		spriteReplay = new Sprite(0, 0, ResourcesManager.getInstance().replay_region, vbom){
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
					float pTouchAreaLocalX, float pTouchAreaLocalY) {
				SceneManager.getInstance().replayGame();
				return true;
			}
		};
		
		spriteReplay.setPosition(420, 400);
		spriteNavigator.attachChild(spriteReplay);
	}
	
	public void display(int Score, Scene scene, Camera camera){
		
		camera.getHUD().setVisible(false);
		camera.setHUD(null);
		camera.setChaseEntity(null);
		setPosition(camera.getXMin(), camera.getYMin());
		scene.registerTouchArea(spriteReplay);
		
		scene.attachChild(this);
	}
}
